//
// Created by Administrator on 2021/10/26.
//

#ifndef MRENDER_MODEL_H
#define MRENDER_MODEL_H


#include "../../core/Object3D.h"
#include "../../geometries/AxiesBufferGeometry.h"

class Model : public Object3D{
private:
    String objFilePath;

    /**
     * 使用数组方式存储解析
     * @param bufferGeometry
     */
    void useArray(BufferGeometry *bufferGeometry);

protected:

    /**
     * 解析顶点数据
     * @param line 文本
     */
    void parseVertex(std::vector<String> line, BufferGeometry *bufferGeometry);

    /**
     * 解析UV数据
     * @param line 文本
     */
    void parseUV(std::vector<String> line, BufferGeometry *bufferGeometry);

    /**
     * 解析法线数据
     * @param line 文本
     */
    void parseNormal(std::vector<String> line, BufferGeometry *bufferGeometry);

    /**
     * 解析索引数据
     * @param line 文本
     */
    void parseIndex(std::vector<String> line, BufferGeometry *bufferGeometry);

public:
    void onInit() override;
    void onRender(float elapsedTime, Matrix4x4 proj, Matrix4x4 view, Matrix4x4 pworld) override;
public:
    Model(String objFilePath);

    std::vector<Vector3> regexVector3Array(const String &objContent, const String &regex) const;

    void parseIndices(String objContent, std::vector<Vector3> v_array, std::vector<Vector3> vt_array,
                 std::vector<Vector3> vn_array, BufferGeometry *bufferGeometry);
};


#endif //MRENDER_MODEL_H
